package com.stylefeng.guns.modular.purchase.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.GoodsReturnList;
import com.stylefeng.guns.modular.purchase.service.IGoodsReturnListService;

import javax.jws.WebParam;

/**
 * 退货单据查询控制器
 *
 * @author fengshuonan
 * @Date 2018-09-12 21:10:21
 */
@Controller
@RequestMapping("/goodsReturnList")
public class GoodsReturnListController extends BaseController {

    private String PREFIX = "/purchase/goodsReturnList/";

    @Autowired
    private IGoodsReturnListService goodsReturnListService;

    /**
     * 跳转到退货单据查询首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "goodsReturnList.html";
    }

    /**
     * 跳转进退货订单详情
     * @param returnListId 退货订单id
     * @param returnOrderNumber 退货订单号码
     * @param model 模型
     * @return 页面
     */
    @RequestMapping("/goodsReturnList_detail/{returnListId}/{returnOrderNumber}")
    public String goodsReturnListDetail(@PathVariable(value = "returnListId") Long returnListId,
                                        @PathVariable(value = "returnOrderNumber") String returnOrderNumber,
                                        Model model){
        model.addAttribute("returnListId", returnListId);
        model.addAttribute("returnOrderNumber", returnOrderNumber);
        return PREFIX + "goodsReturnList_detail.html";
    }

    /**
     * 获取退货单据查询列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return goodsReturnListService.selectList(null);
    }

    /**
     * 新增退货单据查询
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(GoodsReturnList goodsReturnList) {
        goodsReturnListService.insert(goodsReturnList);
        return SUCCESS_TIP;
    }

    /**
     * 删除退货单据查询
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer goodsReturnListId) {
        goodsReturnListService.deleteById(goodsReturnListId);
        return SUCCESS_TIP;
    }

    /**
     * 退货单据查询详情
     */
    @RequestMapping(value = "/detail/{goodsReturnListId}")
    @ResponseBody
    public Object detail(@PathVariable("goodsReturnListId") Long goodsReturnListId) {
        EntityWrapper<GoodsReturnList> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("return_goods_list_id", goodsReturnListId);
        return goodsReturnListService.selectList(entityWrapper);
    }
}
